function Generate_Excel_STAT_tables(Data_Summary, Placeness_MetaData)
% This script writes the matlab tables generated to excel sheets that are
% usable for further statistical analysis in Rstudio

% IMPORTANT NOTE: Before you generate output excel sheets, make sure that in getdsap.m
% function, change the dataset file names & paths to match the one you wish
% to examine!!!!!!

% get output directories
[ds, ~] = getdsap;

% generate matlab tables summarizing data
[mean_RM, mean_PV, RM_rotation, PV_rotation, ER_correlation, Mean_Event_Rate, Cell_Recurring_Probability, MI_and_pMI, RM_correlation, Shuffled_RM_correlation, PV_correlation, Shuffled_PV_correlation, Active_Cell_Proportion, Mobility, Event_Rate] = Make_Tables_for_STAT(Data_Summary, Placeness_MetaData);

% list all directories to write the tables as excel sheets
mean_RM_path = fullfile(ds.metadataPath, 'mean_RM.xlsx');
mean_PV_path = fullfile(ds.metadataPath, 'mean_PV.xlsx');
RM_path = fullfile(ds.metadataPath, 'RM_correlation.xlsx');
RM_shuffle_path = fullfile(ds.metadataPath, 'Shuffled_RM_correlation.xlsx');
PV_path = fullfile(ds.metadataPath, 'PV_correlation.xlsx');
PV_shuffle_path = fullfile(ds.metadataPath, 'Shuffled_PV_correlation.xlsx');
RM_rot_path = fullfile(ds.metadataPath, 'RM_rotation.xlsx');
PV_rot_path = fullfile(ds.metadataPath, 'PV_rotation.xlsx');
ER_corr_path = fullfile(ds.metadataPath, 'ER_correlation.xlsx');
mean_ER_path = fullfile(ds.metadataPath, 'mean_ER.xlsx');
cell_recurr_prob_path = fullfile(ds.metadataPath, 'cell_recurring_probability.xlsx');
MI_pMI_path = fullfile(ds.metadataPath, 'MI_and_pMI.xlsx');
active_cell_proportion_path = fullfile(ds.metadataPath, 'active_cell_proportion.xlsx');
ER_path = fullfile(ds.metadataPath, 'ER.xlsx');
mobility_path = fullfile(ds.metadataPath, 'Mobility.xlsx');

% start writing the tables to .xlsx
writetable(mean_RM, mean_RM_path);
writetable(mean_PV, mean_PV_path);
writetable(RM_rotation, RM_rot_path);
writetable(PV_rotation, PV_rot_path);
writetable(ER_correlation, ER_corr_path);
writetable(Mean_Event_Rate, mean_ER_path);
writetable(Cell_Recurring_Probability, cell_recurr_prob_path);
writetable(MI_and_pMI, MI_pMI_path);
writetable(RM_correlation, RM_path);
writetable(Shuffled_RM_correlation, RM_shuffle_path);
writetable(PV_correlation, PV_path);
writetable(Shuffled_PV_correlation, PV_shuffle_path)
writetable(Active_Cell_Proportion, active_cell_proportion_path);
writetable(Mobility, mobility_path);
writetable(Event_Rate, ER_path);

end